package jblip.gui.components.tree;

import java.awt.Image;

import javax.swing.ImageIcon;

import jblip.gui.JBlip;
import jblip.gui.data.channels.UserDataChannel;
import jblip.gui.data.images.ImageChangeListener;
import jblip.resources.UserPicture.PictureSize;

public class UserChannelNode extends UpdatesChannelNode implements
    ImageChangeListener {
  private static final long serialVersionUID = 2L;

  private static final ImageIcon DEFAULT_USER_ICON;

  static {
    DEFAULT_USER_ICON =
        new ImageIcon(UpdatesChannelNode.class
            .getResource("/jblip/gui/resources/femto_anon.png"));
  }

  private ImageIcon current_icon;

  public UserChannelNode(final ChannelTreeModel model,
      final UserDataChannel data) {
    super(model, data);
    final String user = data.getUserName();
    current_icon = DEFAULT_USER_ICON;
    JBlip.instance().getIconCache().getUserIcon(user, PictureSize.FEMTO, this);
  }

  @Override
  public ImageIcon getIcon() {
    return current_icon;
  }

  @Override
  public void imageChange(final Image new_image) {
    current_icon = new ImageIcon(new_image);
    tree_model.nodeChanged(this);
  }
}
